<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>编辑商品类别</h2>


<input type="hidden" id="txtTno">
<input placeholder="请输入类别名称" id="txtType">

<button type="button" id="btnSaveType">保存</button>
</body>

<script src="js/jquery-3.2.1.js"></script>
<script src="js/layer/layer.js"></script>

<script>

    var url = location.href;
    console.log(url);
    var params = url.split('?')[1];
    var tno = params.split('=')[1];
    console.log(tno);

    $(function () {
        $.getJSON('query_type_id.do', {tno: tno}, function (data) {
            //console.log(data);
            if (data.code == 200) {
                $('#txtTno').val(data.result.tno);
                $('#txtType').val(data.result.tname);
            }
        })

        $('#btnSaveType').click(function () {
            $.post('update_type.do', {
                tno: $('#txtTno').val(),
                tname: $('#txtType').val()
            }, function (data) {
                //console.log(data);
                if (data.code == 200) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.href = "category_list.html";
                    })
                } else {
                    layer.msg(data.msg);
                }
            }, "json")
        })
    })

</script>
</html>